package com.jctrip.hotel.source.xxl.hworld.thread;

import org.apache.commons.lang.StringUtils;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.service.hworld.HworldTaskService;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author henry
 * @Date 2023/5/29 22:19
 * @Description
 */
@Slf4j
public class SyncHworldHotelIdTaskThread implements Runnable{
    private final String appId;

    private final String key;


    public SyncHworldHotelIdTaskThread(String appId, String key) {
        this.appId = appId;
        this.key = key;
    }

    @Override
    public void run() {
        try {
            RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);
            HworldTaskService hworldTaskService = BeanContext.getApplicationContext().getBean(HworldTaskService.class);

            while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_HWORLD_HOTELID_LIST) > 0) {
                try {
                    String hotelId = (String) redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_HWORLD_HOTELID_LIST);
                    if (StringUtils.isBlank(hotelId)) {
                        continue;
                    }

                    hworldTaskService.syncHworldHotelIdListTask(appId, key, hotelId);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

    }
}
